
// Juxtagate class
function juxtagate()
{
	// This is our keyring :)
	var gateKeys = [];
	
	// Some internal variables
	this.foundGate = false;
	this.debug = true;
	this.retryTimer = setTimeout( "jx.start();", 1000 );
	
	this.log( "Init" );
	
	// Add a key to the keyring
	this.addKey = function( key )
	{
		gateKeys.push( key );
	}
	
	// Starts the process of searching for the correct key
	this.start = function()
	{
		this.log( "Starting keyring search:" );
		
		// Attempt each gate key
		for ( var i = 0; i < gateKeys.length; i++ )
		{
			gateKeys[ i ]();
		}
		
		this.log( "Search complete!" );
	}
	
	// Called after a key is used
	this.usedKey = function()
	{
		// Display icon
		chrome.extension.sendRequest({}, function(response) {});
		
		this.foundGate = true;
		clearTimeout( this.retryTimer );
	}
}

// Write a message to the console
juxtagate.prototype.log = function( message )
{
	if ( !this.debug )
		return;
		
	console.log( "Juxtagate: " + message );
}

// Helper function for checking numeric values
juxtagate.prototype.isNum = function( val )
{
	return !( isNaN( parseInt( val ) ) );
}

// Create global object
var jx = new juxtagate();
